<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "data_relationship".
 *
 * @property integer $id
 * @property integer $user_id
 * @property integer $content_id
 * @property integer $class1_id
 * @property integer $class2_id
 * @property string $last_time
 * @property string $answer
 * @property string $user_key
 * @property string $t_time
 * @property string $reading_practice
 * @property string $que_option
 *
 * @property Class1 $class1
 * @property Class2 $class2
 * @property User $user
 */
class DataRelationship extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'data_relationship';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'content_id', 'class1_id', 'class2_id'], 'required'],
            [['user_id', 'content_id', 'class1_id', 'class2_id'], 'integer'],
            [['last_time'], 'safe'],
            [['answer', 'user_key', 't_time', 'reading_practice', 'que_option'], 'string'],
            [['class1_id'], 'exist', 'skipOnError' => true, 'targetClass' => Class1::className(), 'targetAttribute' => ['class1_id' => 'id']],
            [['class2_id'], 'exist', 'skipOnError' => true, 'targetClass' => Class2::className(), 'targetAttribute' => ['class2_id' => 'id']],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'user_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'content_id' => 'Content ID',
            'class1_id' => 'Class1 ID',
            'class2_id' => 'Class2 ID',
            'last_time' => 'Last Time',
            'answer' => 'Answer',
            'user_key' => 'User Key',
            't_time' => 'T Time',
            'reading_practice' => 'Reading Practice',
            'que_option' => 'Que Option',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getClass1()
    {
        return $this->hasOne(Class1::className(), ['id' => 'class1_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getClass2()
    {
        return $this->hasOne(Class2::className(), ['id' => 'class2_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['user_id' => 'user_id']);
    }
}
